<!DOCTYPE html>
<html class="no-js" lang="en" xmlns:v-on="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8">
    <title>模板</title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!--====== Favicon Icon ======-->
    <link rel="shortcut icon" href="assets/images/favicon.png" type="image/png">
    <!--====== Magnific Popup CSS ======-->
    <link rel="stylesheet" href="assets/css/magnific-popup.css">
    <!--====== Slick CSS ======-->
    <link rel="stylesheet" href="assets/css/slick.css">
    <!--====== Line Icons CSS ======-->
    <link rel="stylesheet" href="assets/css/LineIcons.css">
    <!--====== Bootstrap CSS ======-->
    <link rel="stylesheet" href="assets/css/bootstrap.min.css">
    <!--====== Default CSS ======-->
    <link rel="stylesheet" href="assets/css/default.css">
    <!--====== Style CSS ======-->
    <link rel="stylesheet" href="assets/css/style.css">

</head>
<body>
<!-- 导入页眉 -->
<div class="header"></div>

<!--====== 自定义代码开始 ======-->
<section id="about" class="about-area">
    <div class="container">

        <div>
            <h4 style="position: absolute;top:40%;left: 10%;">普通用户展示</h4>
        </div>

        <!--====== 从这里开始 ======-->
        <div class="row col-sm-6 offset-md-3" style="margin-top: 5%;" id="div_vue">
            <table class="table">
                <thead class="thead-dark">
                <tr>
                    <th scope="col">用户名</th>
                    <th scope="col">最近登录时间</th>
                    <th scope="col">移除该用户</th>
                    <th scope="col">设置为管理员</th>
                </tr>
                </thead>
                <tr v-for="user in userList">
                    <th scope="row" :id="user.userName">{{user.userName}}</th>
                    <td>{{user.lastLoginTime}}</td>
                    <td>
                        <button type="button" class="btn btn-primary" v-on:click="deleteUser" :userName="user.userName">
                            删除用户
                        </button>
                    </td>
                    <td>
                        <button type="button" class="btn btn-primary" @click="setAdmin(user.id,user.userName)" >
                            设为管理员
                        </button>
                    </td>
                </tr>
            </table>
        </div>
        <!--====== 导入右边导航栏 ======-->
        <div class="admin-nav"></div>
        <!--====== 从这里结束 ======-->
    </div> <!-- container -->

</section>
<!--====== 自定义代码结束 ======-->


<!-- 导入页脚 -->
<div class="footer"></div>
<!--导入所有js文件-->
<!--====== Jquery js ======-->
<script src="assets/js/vendor/jquery-1.12.4.min.js"></script>
<script src="assets/js/vendor/modernizr-3.7.1.min.js"></script>
<!--====== Bootstrap js ======-->
<script src="assets/js/popper.min.js"></script>
<script src="assets/js/bootstrap.min.js"></script>
<!--====== Slick js ======-->
<script src="assets/js/slick.min.js"></script>
<!--====== Magnific Popup js ======-->
<script src="assets/js/jquery.magnific-popup.min.js"></script>
<!--====== Ajax Contact js ======-->
<script src="assets/js/ajax-contact.js"></script>
<!--====== Isotope js ======-->
<script src="assets/js/imagesloaded.pkgd.min.js"></script>
<script src="assets/js/isotope.pkgd.min.js"></script>
<!--====== Scrolling Nav js ======-->
<script src="assets/js/jquery.easing.min.js"></script>
<script src="assets/js/scrolling-nav.js"></script>
<!--====== Main js ======-->
<script src="assets/js/main.js"></script>
<!--======vue js ======-->
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<!--======HttpUtil js ======-->
<script src="assets/js/util/HttpUtil.js"></script>

</body>
</html>
<script type="text/javascript">
    //在js中引入页眉页脚
    $(document).ready(function () {
        $('.header').load('header.html');
        $('.footer').load('footer.html');
        $('.admin-nav').load('admin-nav.html');
    });
    var vm = null;
    $(function () {
        showUser();
    });
    var name=null;
    function showUser() {
        vm = new Vue({
            el: '#div_vue',
            data: {
                userList: []
            },
            methods: {
                refreshUserList: function () {
                    //发起http请求后台获取商家列表数据
                    let url = "showList.do";
                    let thisObj = this;
                    doGet(url, function (data) {
                        thisObj.userList = data;
                    })
                },
                deleteUser: function (e) {
                    var that = e.target;
                    console.log($(that).attr("userName"));
                    var userName = $(that).attr("userName");
                    console.log(userName+"1111");
                    let url = "delete.do";
                    //let userNameVal = $("#th_1").text();
                    //console.log(userNameVal);
                    let params = {userName: userName};
                    var flag = confirm("确认要删除用户？");
                    if (!flag){
                        return;
                    }
                    getWithParams(url, params, function (resp) {
                        console.log(resp);
                        //showUser();
                        location.href = "http://localhost:8080/blog_view/userlist.html";
                    })
                },
                setAdmin:function (userId,userName) {
                    name=userName;
                    console.log(userId);
                   let url="setAdmin.do";
                   let params={userId:userId};
                   postWithoutJson(url,params,function (resp) {
                       alert("恭喜"+name+"称为兰州博客管理员");
                       console.log(resp);
                   })
                }
            },
            mounted: function () {
                //页面加载完成，并且vue对象加载完成之后调用
                this.refreshUserList();
            },
            created: function () {
                console.log("created");
            }
        });
    }


</script>